package com.mydemo.game.hireStage;

import com.mydemo.entity.Driver;
import com.mydemo.entity.Save;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class HireDriver {
    public static final boolean hireDriver(Save save, Driver driver) {
        System.out.println(driver.getName() + " 的日薪是：" + driver.getSalary());
        System.out.print("请输入需要雇佣的天数,输入0退出：");
        Scanner scanner = new Scanner(System.in);
        int days = scanner.nextInt();
        if (days == 0) {
            return false;
        } else if (days * driver.getSalary() > save.getMoney()) {
            System.out.println("你的资金不足，已自动取消雇佣");
            return false;
        } else {
            save.setMoney(save.getMoney() - days * driver.getSalary());
            driver.setDays(days);
            List<Driver> list;
            if (save.getDriverList() == null) {
                driver.setId(1);
                list = new ArrayList<>();
            } else {
                list = save.getDriverList();
                int id = list.stream()
                        .mapToInt(Driver::getId)
                        .max()
                        .orElse(0) + 1;
                driver.setId(id);
                driver.setId(id);
            }
            list.add(driver);
            save.setDriverList(list);
            return true;
        }
    }
}
